{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1, 3, 5, 7] [1, 2, 3, 4, 5, 6, 7]\n"
     ]
    }
   ],
   "source": [
    "#python 如何在不用嵌套的情况下提取出列表中的奇数？\n",
    "list_a = [1,2,3,4,5,6,7]\n",
    "b = [a for a in list_a if a %2 != 0]\n",
    "c = [a if a %2 != 0 else a for a in list_a ]\n",
    "#b = [True if a %2 != 0 else False  for a in list_a]\n",
    "#c = list_a[b]\n",
    "print(b,c)\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3.9.12 ('base')",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  },
  "orig_nbformat": 4,
  "vscode": {
   "interpreter": {
    "hash": "ad2bdc8ecc057115af97d19610ffacc2b4e99fae6737bb82f5d7fb13d2f2c186"
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
